﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/AdminDefault.Master"
  AutoEventWireup="true" CodeBehind="Video.aspx.cs" Inherits="ITViet.Web.Admin.Video" %>

<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dxcb" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxUploadControl" TagPrefix="dxuc" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxDataView" TagPrefix="dxdv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div>
    <div style="padding-bottom: 10px;">
      <dxe:ASPxCheckBox ID="ckbAll" ClientInstanceName="ckbAll" Text="<%$Resources:Strings, SelectAllItem %>"
        runat="server" Cursor="pointer" AutoPostBack="false">
        <ClientSideEvents CheckedChanged="function(s,e){ckbAll_Click();}" />
      </dxe:ASPxCheckBox>
    </div>
    <dxdv:ASPxDataView ID="dvVideo" ClientInstanceName="dvVideo" ColumnCount="4" runat="server"
      RowPerPage="2" OnCustomCallback="dvVideo_CustomCallback" OnCustomJSProperties="dvVideo_CustomJSProperties"
      OnDataBound="dvVideo_DataBound">
      <ContentStyle Paddings-Padding="5px">
      </ContentStyle>
      <PagerStyle>
        <Paddings Padding="0px" />
      </PagerStyle>
      <ItemStyle Height="160px" Width="160px">
        <Paddings PaddingTop="0px" PaddingBottom="0px" PaddingLeft="0px" PaddingRight="0px" />
      </ItemStyle>
      <ItemTemplate>
        <div style="width: 155px; padding-bottom: 3px;" align="center">
          <asp:Label ID="Label1" runat="server" Text='<%#Eval("Name")%>' Font-Bold="True" ForeColor="#238787"></asp:Label>
          <input id="item_checkbox" name="delete" title='<%#Eval("Id")%>' type="checkbox" style="cursor: pointer;
            padding-top: 3px;" />
        </div>
        <div style="border: 1px solid #ADB8AF; width: 155px;">
          <asp:Literal ID="Videoplay" runat="server" Text='<%#Eval("Path") %>'></asp:Literal>
        </div>
        <div style="width: 155px; padding-top: 8px;" align="center">
          <asp:Label ID="Label3" runat="server" Text="<%$Resources:Strings, ShowOnHome%>" CssClass="CommonFont"
            ForeColor="#006699"></asp:Label>
          <input title='<%#Eval("Id")%>' name="active" type="radio" style="cursor: pointer; padding-top: 3px;" onclick="changeStatus('<%#Eval("Id")%>')"
            <%# Eval("Status")%> />
        </div>
      </ItemTemplate>
      <PagerSettings Position="Bottom">
      </PagerSettings>
      <ClientSideEvents EndCallback="function(s,e){dvVideo_EndCallback(s,e)}" />
    </dxdv:ASPxDataView>
    
    <div style="float: left; padding-left: 3px; padding-top: 10px;">
      <dxe:ASPxButton ID="btnAdd" Text="<%$Resources:Strings, Add%>" AutoPostBack="false"
        ClientInstanceName="btnAdd" runat="server">
        <ClientSideEvents Click="function (s,e){btnAdd_Click();}" />
      </dxe:ASPxButton>
    </div>
    <div style="float: left; padding-left: 3px; padding-top: 10px;">
      <dxe:ASPxButton ID="btnSaveState" Text="<%$Resources:Strings, Save%>" AutoPostBack="false"
        ClientInstanceName="btnSaveState" runat="server">
        <ClientSideEvents Click="function (s,e){btnSaveChangeStatus_Click();}" />
      </dxe:ASPxButton>
    </div>
    <div style="float: left; padding-left: 3px; padding-top: 10px;">
      <dxe:ASPxButton ID="btnDelete" Text="<%$Resources:Strings, Delete%>" AutoPostBack="false"
        ClientInstanceName="btnDelete" runat="server">
        <ClientSideEvents Click="function (s,e){btnDelete_Click();}" />
      </dxe:ASPxButton>
    </div>
  </div>
  <div>
    <dxpc:ASPxPopupControl ID="pcVideo" ClientInstanceName="pcVideo" runat="server" Width="400px"
      Modal="true" CloseAction="CloseButton" PopupVerticalAlign="WindowCenter" AllowDragging="True"
      EnableViewState="False" PopupHorizontalAlign="WindowCenter" HeaderText="<%$Resources:Strings, Video %>">
      <ModalBackgroundStyle BackColor="Black">
      </ModalBackgroundStyle>
      <SizeGripImage Height="12px" Width="12px" />
      <ContentCollection>
        <dxpc:PopupControlContentControl>
          <div style="padding-bottom: 3px; width: 100%">
            <dxe:ASPxLabel ID="lblErrorMessage" ClientInstanceName="lblErrorMessage" runat="server"
              Font-Bold="True" ForeColor="Red" ClientVisible="true">
            </dxe:ASPxLabel>
          </div>
          <table style="padding: 10px;" width="100%" class="CommonFont">
            <tr>
              <td>
                <asp:Label ID="Label11" runat="server" Text="<%$ Resources:Strings, Name %>"></asp:Label>
              </td>
              <td>
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtName" ClientInstanceName="txtName" runat="server" Width="170px">
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label7" runat="server" Text="<%$ Resources:Strings, UploadFile %>"></asp:Label>
              </td>
              <td>
              </td>
              <td>
                <div>
                  <dxuc:ASPxUploadControl ID="uploader" ClientInstanceName="uploader" runat="server"
                    Width="230px" OnFileUploadComplete="uploader_FileUploadComplete">
                    <ProgressBarStyle Height="25px">
                    </ProgressBarStyle>
                    <ValidationSettings FileDoesNotExistErrorText="NOT_EXIST" GeneralErrorText="GENERAL_ERR"
                       MaxFileSizeErrorText="MAX_SIZE" NotAllowedContentTypeErrorText="ERROR_TYPE">
                      <ErrorStyle Font-Size="0pt" />
                    </ValidationSettings>
                    <ClientSideEvents FileUploadComplete="function(s,e){uploader_FileUploadComplete(s,e);}" />
                  </dxuc:ASPxUploadControl>
                </div>
                <div style="padding-bottom: 3px; padding-top: 4px;">
                  <asp:Label ID="lblUploadCondition" runat="server" Text="<%$ Resources:Strings,MaxFile %>"></asp:Label><br />
                  <asp:Label ID="Label4" runat="server" Text="<%$ Resources:Strings,VideoType %>"></asp:Label>
                </div>
              </td>
            </tr>
            <tr>
              <td>
              </td>
              <td>
              </td>
              <td>
                <div style="float: left;">
                  <dxe:ASPxButton ID="btnSave" Text="<%$ Resources:Strings, Save %>" ClientInstanceName="btnSave"
                    AutoPostBack="false" runat="server">
                    <ClientSideEvents Click="function (s,e){btnSave_Click();}" />
                  </dxe:ASPxButton>
                </div>
                <div style="float: left; padding-left: 5px;">
                  <dxe:ASPxButton ID="btnCancel" Text="<%$ Resources:Strings, Cancel %>" ClientInstanceName="btnCancel"
                    AutoPostBack="false" runat="server">
                    <ClientSideEvents Click="function (s,e){btnCancel_Click();}" />
                  </dxe:ASPxButton>
                </div>
              </td>
            </tr>
          </table>
        </dxpc:PopupControlContentControl>
      </ContentCollection>
      <CloseButtonImage Height="17px" Width="17px"></CloseButtonImage>
      <HeaderStyle>
        <Paddings PaddingLeft="10px" PaddingRight="6px" PaddingTop="1px" />
      </HeaderStyle>
    </dxpc:ASPxPopupControl>
    <asp:HiddenField ID="hfPath" runat="server"/>
    <asp:HiddenField ID="hfListId" runat="server"/>
    <asp:Literal ID="tt" runat="server"></asp:Literal>
    <script type="text/javascript" language="javascript">
      function dvVideo_EndCallback(s,e) {
        var error = dvVideo.cpInnerError;
        if (error.indexOf("ERROR|") != -1) {
          alertMessage(error.split('|')[1]); 
        }
        else {
          pcVideo.Hide();
        }
        txtName.SetText('');
        uploader.ClearInputText();
      }
      
      function btnAdd_Click() {
        pcVideo.Show();
      }
      
      function btnSave_Click() {
        pcWaiting.Show();
        uploader.Upload();
      }
      
      function btnCancel_Click() {
        pcVideo.Hide();
        uploader.ClearInputText();
        txtName.SetText("");
      }
      
      function uploader_FileUploadComplete(s, e) {
        pcWaiting.Hide();
        if (e.isValid) {
          document.getElementById('<%=hfPath.ClientID %>').value = e.callbackData
          dvVideo.PerformCallback("save|");
        }
        else {
          lblErrorMessage.SetText(e.errorText);
        }
      }
      
      function ckbAll_Click() {
        var chblist = document.getElementById('<%=dvVideo.ClientID %>').getElementsByTagName('input');
        for (i = 0; i < chblist.length; i++) {
          if (chblist[i].type == "checkbox" && chblist[i].name=="delete") {
            chblist[i].checked = ckbAll.GetValue();
          }
        }
      }
      
      function ckbAllActive_Click() {
        var chblist = document.getElementById('<%=dvVideo.ClientID %>').getElementsByTagName('input');
        for (i = 0; i < chblist.length; i++) {
          if (chblist[i].type == "checkbox" && chblist[i].name=="active") {
            chblist[i].checked = ckbAllActive.GetValue();
          }
        }
      }
      
      function btnDelete_Click() {
        var LId = "";
        var chblist = document.getElementById('<%=dvVideo.ClientID %>').getElementsByTagName('input');
        for (i = 0; i < chblist.length; i++) {
          if (chblist[i].type == "checkbox" && chblist[i].name=="delete" && chblist[i].checked) {
            LId += chblist[i].title + ',';
          }
        }
        if (LId != "") {
          document.getElementById('<%=hfListId.ClientID %>').value = LId.substr(0,LId.length-1); 
          dvVideo.PerformCallback('delete');
        }
      }
      
      function btnSaveState_Click() {
        var LId = "";
        var NLId=""
        var chblist = document.getElementById('<%=dvVideo.ClientID %>').getElementsByTagName('input');
        for (i = 0; i < chblist.length; i++) {
          if (chblist[i].type == "checkbox" && chblist[i].name == "active") {
            if (chblist[i].checked)
              LId += chblist[i].title + ',';
            else
              NLId += chblist[i].title + ',';
          }
        }
        if (LId!='')
          LId = LId.substr(0, LId.length - 1);
        //if (NLId!='')
          LId += ";" + NLId.substr(0, NLId.length - 1);
        //alert(LId); return;
        if (LId != "") {
          document.getElementById('<%=hfListId.ClientID %>').value = LId;
          dvVideo.PerformCallback('state');
        }
      }

      function changeStatus(id) {
        document.getElementById('<%=hfListId.ClientID %>').value = id;
      }

      function btnSaveChangeStatus_Click() {
        if (document.getElementById('<%=hfListId.ClientID %>').value != '') {
          dvVideo.PerformCallback('state');
        }
      }
    </script>

  </div>
</asp:Content>
